/*
 Copyright (C) 2010 QDSS.org
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.qdss.bizz.security.member;

import java.io.Serializable;

import org.qdss.bizz.privileges.Identity;

/**
 * 成员
 * 
 * @author <a href="mailto:zhaofang123@gmail.com">Zhao Fangfang</a>
 * @since 0.2, 2010-10-4
 * @version $Id: Member.java 7 2011-05-15 16:40:50Z zhaofang123@gmail.com $
 */
public class Member implements Identity {
	private static final long serialVersionUID = -108698555460795334L;
	
	private Serializable identity;
	private String name;
	private boolean disabled;
	
	/**
	 * @param identity
	 * @param name
	 */
	public Member(Serializable identity, String name) {
		this(identity, name, Boolean.FALSE);
	}
	
	/**
	 * @param identity
	 * @param name
	 * @param disabled
	 */
	public Member(Serializable identity, String name, boolean disabled) {
		this.identity = identity;
		this.name = name;
		this.disabled = disabled;
	}
	
	@Override
	public Serializable getIdentity() {
		return identity;
	}

	/**
	 * Returns 0
	 */
	@Override
	public int getMask() {
		return 0;
	}

	@Override
	public String getName() {
		return name;
	}
	
	/**
	 * @param disabled
	 */
	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}
	
	/**
	 * @return
	 */
	public boolean isDisabled() {
		return disabled;
	}
	
	@Override
	public int hashCode() {
		int h = System.identityHashCode(getIdentity());
		h += ~(h << 9);
		h ^= (h >>> 14);
		h += (h << 4);
		h ^= (h >>> 10);
		return h;
	}
	
	@Override
	public boolean equals(Object o) {
		if (o == null)
			return false;
		return hashCode() == o.hashCode();
	}
	
	/**
	 * Returns NAME:ID:DISABLED@super#toString
	 */
	@Override
	public String toString() {
		return new StringBuffer(getName()).append(':').append(getIdentity())
				.append(':').append(isDisabled() ? 0 : 1).append('@').append(
						super.toString()).toString();
	}
}
